package cn.sciento.farm.devicemanager.gateway.uplink.service.screen;

import cn.sciento.farm.devicemanager.common.constant.MqttConstant;
import cn.sciento.farm.devicemanager.gateway.uplink.service.base.AbstractStringAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;

@Service(value = MqttConstant.PROTOCOL_PREFIX + MqttConstant.PROTOCOL_SCREEN)
public class ScreenDataAdapter extends AbstractStringAdapter {

    @Autowired
    private ScreenDisposeService screenDisposeService;

    @Override
    public void analyseStringData(String[] subTopic, String message) {
        if(subTopic.length >3){
            return;
        }
        String eui = subTopic[2];

        try {
            screenDisposeService.trigger(eui);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
